package com.vincent.kdp.Activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.vincent.kdp.R;
import com.vincent.kdp.http.RequestCallBack;
import com.vincent.kdp.ui.bean.response.NoticeNumOutput;
import com.vincent.kdp.ui.notice.repository.NoticeRepository;
import com.vincent.kdp.ui.other.MainActivity;
import com.vincent.kdp.view.BadgeView;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.github.xudaojie.qrcodelib.CaptureActivity;

public class NoticeActivity extends AppCompatActivity  {

    @Bind(R.id.yingxiao)
    TextView yingxiao;
    @Bind(R.id.renli)
    TextView renli;
    @Bind(R.id.peixun)
    TextView peixun;
    @Bind(R.id.jinjia)
    TextView jinjia;
    @Bind(R.id.yunying)
    TextView yunying;
    @Bind(R.id.qiri)
    TextView qiri;
    @Bind(R.id.shengri)
    TextView shengri;

    @Bind(R.id.yingxiaoWrap)
    LinearLayout yingxiaoWrap;
    @Bind(R.id.renliWrap)
    LinearLayout renliWrap;
    @Bind(R.id.peixunWrap)
    LinearLayout peixunWrap;
    @Bind(R.id.jinjiaWrap)
    LinearLayout jinjiaWrap;
    @Bind(R.id.yunyingWrap)
    LinearLayout yunyingWrap;
    @Bind(R.id.qiriWrap)
    LinearLayout qiriWrap;
    @Bind(R.id.shengriWrap)
    LinearLayout shengriWrap;

    @Bind(R.id.yingxiaoBadge)
    TextView yingxiaoBadge;
    @Bind(R.id.renliBadge)
    TextView renliBadge;
    @Bind(R.id.peixunBadge)
    TextView peixunBadge;
    @Bind(R.id.jinjiaBadge)
    TextView jinjiaBadge;
    @Bind(R.id.yunyingBadge)
    TextView yunyingBadge;
    @Bind(R.id.qiriBadge)
    TextView qiriBadge;
    @Bind(R.id.shengriBadge)
    TextView shengriBadge;


    @Bind(R.id.back_img)
    ImageView mBackImg;
    @Bind(R.id.toolbar_center_tv)
    TextView mToolbarCenterTv;

    private NoticeRepository noticeRepository=new NoticeRepository();

    private NoticeActivity thisActivity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notice);
        thisActivity=this;
        ButterKnife.bind(this);
        mToolbarCenterTv.setText("通知");
        mBackImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                back();
            }
        });
        reqAllNoticeNum();
    }

    private void reqAllNoticeNum(){
        reqNoticeNum("1",yingxiao);
        reqNoticeNum("2",renli);
        reqNoticeNum("3",peixun);
        reqNoticeNum("4",jinjia);
        reqNoticeNum("5",yunying);
        reqNoticeNum("14",qiri);
        reqNoticeNum("15",shengri);
    }

    private void reqNoticeNum(String type,final TextView textView){
        noticeRepository.reqCountNoticeNum(type,new  RequestCallBack< NoticeNumOutput>(){
            @Override
            public void onSuccess(NoticeNumOutput numOutput) {
                BadgeView badgeView = new BadgeView(thisActivity);
                badgeView.setTargetView(textView);
                badgeView.setBadgeGravity(Gravity.CENTER|Gravity.RIGHT);
                badgeView.setBadgeCount(0);
                badgeView.setBadgeCount(numOutput.getData().getNoticeNum());
            }

            @Override
            public void onFalse(String msg) {

            }
        });
    }

    @OnClick({R.id.yingxiaoWrap})
    public void onClick_yingxiao(View view) {
        toList(1);
    }
    @OnClick({R.id.renliWrap})
    public void onClick_renli(View view) {
        toList(2);
    }
    @OnClick({R.id.peixunWrap})
    public void onClick_peixun(View view) {
        toList(3);
    }
    @OnClick({R.id.jinjiaWrap})
    public void onClick_jinjia(View view) {
        toList(4);
    }
    @OnClick({R.id.yunyingWrap})
    public void onClick_yunying(View view) {
        toList(5);
    }
    @OnClick({R.id.qiriWrap})
    public void onClick_qiri(View view) {
        toList(14);
    }
    @OnClick({R.id.shengriWrap})
    public void onClick_shengri(View view) {
        toList(15);
    }

    private void back(){
        this.finish();
        overridePendingTransition(com.vincent.baseapp.R.anim.fragment_left_in, com.vincent.baseapp.R.anim.fragment_right_out);
    }

    private void toList(int type){
        Intent intent=new Intent(NoticeActivity.this,NoticeListActivity.class);
        intent.putExtra("type",type);
        startActivity(intent);
        finish();
    }

}
